const express = require("express");
const router = express.Router();
const { default: mongoose } = require("mongoose");

// 获取 schema
const { Schema } = mongoose;
const url = "mongodb://127.0.0.1:27017/shopApp";
mongoose.connect(url)
    .then(() => console.log("链接成功数据库"))
    .catch(err => console.error("连接数据库失败:", err));

// 查找数据
// 创建数据模版
const detailData = mongoose.model("getDetail")
// 详情数据
router.get("/getAdd", async (req, res, next) => {
    try {
        let data = await detailData.find({})
        console.log("详情数据", data[0]);
        return res.status(200).json({
            msg: "okok",
            code: 200,
            data: data
        })
    }
    catch (err) {
        return next({
            code: 1001,
            error: err.message,
            errDic: 'hhhhhhhhh'
        })
    }
})

module.exports = router;